/**
 * Created by JetBrains PhpStorm.
 * Author: yzg yangzhiguo0903@163.com
 * Date: 11-12-25
 * Time: 下午4:29
 * To change this template use File | Settings | File Templates.
 */
(function($){
    $.fn.mtDrag = function(mdiv){
        var t = this;
        return t.each(
            function(){
                t.bind('mousedown', {e : $(mdiv)},
                    function(v){
                        var d=v.data, p={}; E=d.e;
                        E.position(p);
                        M = {X : p.left || f('left') || 0, Y : p.top || f('top') || 0, pX: v.pageX, pY: v.pageY};
                        $(this).mousemove($.mtDnR.drag).mouseup($.mtDnR.stop);
                    });
            });
    };
    $.mtDnR={ dnr:{}, e: '',
        drag:function(v){
            var l = (M.X + v.pageX - M.pX) + 'px', t = (M.Y + v.pageY - M.pY) + 'px';
            E.css({left:l, top:t});
        },
        stop:function(){
            $(this).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
        }
    };
    var J = $.mtDnR,M=J.dnr,E=J.e,f = function(k){return parseInt(E.css(k)) || false;};
})(jQuery);